<?php
if($_SERVER["PHP_SELF"] != $CONFIG['phpself'])
exit();
?>
<div id="partone">
<div class="editpart">
<?php

//Verifications.
$sql = "SELECT COUNT(id) AS `id` FROM `achmw_categories`;";
$result = mysql_query($sql);
$data = mysql_fetch_assoc($result);
$countID = intval($data['id']);	

if($countID==0)
{
?><br/>
<table style="text-align: left; width: 734px; height: 196px;"
 border="0" cellpadding="0" cellspacing="10">
  <tbody>
    <tr>
      <td style="width: 184px;"><img
 style="width: 184px; height: 184px;" alt="Attention"
 src="http://media.steampowered.com/steamcommunity/public/images/avatars/6d/6db2ac365ae4ee52c350ac4e9a34fdbf013c64ce_full.jpg"></td>
      <td style="width: 530px;"><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_ERROR[$Lang]; ?></td>
    </tr>
  </tbody>
</table>
<br/><br/>
<?php
}
else
{
?>
<script type="text/javascript">

function valider(){
	var error = 0;
	if(document.formSaisie.title.value == "") {
		error = 1;
	}
	if(document.formSaisie.descr.value == "" && error == 0) {
		error = 2;
	}
	if(document.formSaisie.category.value == -1 && error == 0) {
		error = 3;
	}
	if(document.formSaisie.amount.value == "" && error == 0) {
		error = 4;
	}
	if(isNaN(document.formSaisie.amount.value)) {
		error = 4;
	}
	var OneLife="";
	for(i = 0; i < document.formSaisie.onelife.length; i++){
		if(document.formSaisie.onelife[i].checked)
		{
			OneLife = document.formSaisie.onelife[i].value;
		}
	}

	if(OneLife == "") {
		error = 5;
	}
	
	var taunt = "";
	for(i = 0; i < document.formSaisie.taunt.length; i++){
		if(document.formSaisie.taunt[i].checked)
		{
			taunt = document.formSaisie.taunt[i].value;
		}
	}

	if(taunt == "") {
		error = 6;
	}

	if (error != 0){
		switch(error)
		{
			case 1: alert("<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_NOTITLE[$Lang]; ?>"); break;
			case 2: alert("<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_NODESCR[$Lang]; ?>"); break;
			case 3: alert("<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_NOCAT[$Lang]; ?>"); break;
			case 4: alert("<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_NOAMOUNT[$Lang]; ?>"); break;
			case 5: alert("<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_NOONELIFE[$Lang]; ?>"); break;
			case 6: alert("<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_NOTAUNT[$Lang]; ?>"); break;
			default:
		}
		return false;
	}
	else
	{
		return true;
	}
}

function eraseall()
{
	document.formSaisie.title.value = "";
	document.formSaisie.descr.value = "";
	document.formSaisie.category.value = "";
	document.formSaisie.amount.value = "";
	document.formSaisie.image.value = "";
	document.formSaisie.time.value = "";
	document.formSaisie.taunt.value = "";
	document.formSaisie.onelife.value = "";
	document.formSaisie.oneround.value = "";
}

function openPopup()
{
	try 
	{
		window.open("../images/list.php",'',"scrollbars=yes,toolbar=no,menubar=no,location=no,status=no,width=450,height=400");
	}
	catch(err) 
	{
		alert("<?php echo $JAVASCRIPTPOPUP[$Lang]; ?>");
	} 
}

</script>
<form action="index.php?page=<?php echo $GET_VAR_PAGE; ?>" method="post" name="formSaisie" onsubmit="return valider()">
<br/>
<table style="text-align: left; width: 100%; height: 32px;"
 border="0" cellpadding="2" cellspacing="10">
  <tbody>
    <tr>
      <td><center>
<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_TITLE_FIELD[$Lang]; ?>
<br><input type="text" id="1" name="title" value="<?php echo $_SESSION['AchTitle'];?>"><br/>
<br>
<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_DESC_FIELD[$Lang]; ?>
<br/><input type="text" id="2" name="descr" value="<?php echo $_SESSION['AchDesc'];?>"><br/>
<br/><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_CAT_FIELD[$Lang]; ?>
<br/><select id="3" name="category"><option value="-1">No category</option>
<?php
$result = mysql_query('SELECT * FROM `achmw_categories`;');
while ($row = mysql_fetch_assoc($result)) :
$max=25; 
$chaine = $row['name'];
if(strlen($chaine)>=$max){$chaine=substr($chaine,0,$max);}  
?>
<option value="<?php echo $row['id'].(($row['id'] == $_SESSION['AchCat'])?'" selected="selected':'');?>"><?php echo $chaine; ?></option>
<?php endwhile; ?>
</select><br/>
<script type="text/javascript" src="../function/function.js"></script>
<br/><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_IMG_FIELD[$Lang]; ?><br/><small><a href="javascript:openPopup();" style="text-decoration:none; color: red;"><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_ACH_IMG[$Lang]; ?></a></small><br/>
<input id="4" type="text" name="image" value="<?php echo $_SESSION['Achimage'];?>"><br/>
<br/><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_AMOUNT_FIELD[$Lang]; ?><br/>
<input id="5" type="text" name="amount" value="<?php echo $_SESSION['Achamount'];?>"><br/>
</center><br/><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_ONELIFE_FIELD[$Lang]; ?><br/>
<input name="onelife" id="7" value="1" type="radio" onclick="onelifeChange()" <?php if($_SESSION['Achonelife'] == "1") echo 'checked="checked"';?>><?php echo $YES[$Lang]; ?><input name="onelife" value="0" type="radio" <?php if($_SESSION['Achonelife'] != "1") echo 'checked="checked"';?>><?php echo $NO[$Lang]; ?> 
<br/><br/><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_ONEROUND_FIELD[$Lang]; ?><br/>
<input name="oneround" id="15" value="2" type="radio" onclick="oneroundChange()" <?php if($_SESSION['Achonelife'] == "2") echo 'checked="checked"';?>><?php echo $YES[$Lang]; ?><input name="oneround" value="0" type="radio" <?php if($_SESSION['Achonelife'] != "2") echo 'checked="checked"';?>><?php echo $NO[$Lang]; ?> 
<br/><br/><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_TAUNT[$Lang]; ?><br/>
<input name="taunt" id="8" value="1" type="radio" <?php if($_SESSION['Achtaunt'] == "1") echo 'checked="checked"';?>><?php echo $YES[$Lang]; ?><input name="taunt" value="0" type="radio" <?php if($_SESSION['Achtaunt'] != "1") echo 'checked="checked"';?>><?php echo $NO[$Lang]; ?> 
<br/><br/><?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_TIME[$Lang]; ?><br/>
<input id="9" type="text" name="timemin" size="5" value="<?php if ($_SESSION['Achtime'] != null && $_SESSION['Achtime'] != "" && $_SESSION['Achtime'] != "-1") echo intval(($_SESSION['Achtime'])/60); else echo "-1"; ?>"> (min)<br/>
<input id="19" type="text" name="timesec" size="5" value="<?php if ($_SESSION['Achtime'] != null && $_SESSION['Achtime'] != "" && $_SESSION['Achtime'] != "-1") 
{
$abc = intval((intval($_SESSION['Achtime'])/60));
echo intval($_SESSION['Achtime']) - ($abc*60); 
}
else echo "-1"; ?>"> (sec)
<br/><center>
<input type="hidden" name="part" value="1"/><input type="hidden" name="id" value="<?php echo $_SESSION['AchId']; ?>"/>
<br/><br/>
<input name="generation" value="Preview" type="button" id ="10" onclick="cliquerSurLeBouton()" style="width:80px"> <input type="button" value="<?php echo $DELETE[$Lang]; ?>" onclick="eraseall();"><br>
</center><br/>
</td>
      <td style="width: 450px; vertical-align: top">
	  <center><img src="http://www.teamfortress.com/classless/images/01_pyro_hat_thumb.jpg">
<div id="popup" style="display: none; width: 450px;" align="center"><br/><br/>
<center>"<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_DO_TEXT[$Lang]; ?>"
<input type="image" id="6" BORDER="1"></center>
</div></td>
    </tr>
  </tbody>
</table>
<center><input name="next" value="<?php echo $ADMIN_CREATION_ACHIEVEMENT_PARTONE_VALID_BUTTON[$Lang]; ?>" type="submit"></center><br>
</form>

<?php
}
?>
</div>
<br/><br/>
</div>